package cn.iocoder.yudao.module.xkfz.controller.admin.excel;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.xkfz.controller.admin.excel.result.CommonExcelResult;
import cn.iocoder.yudao.module.xkfz.domain.excel.entity.AchievementAward;
import cn.iocoder.yudao.module.xkfz.domain.excel.entity.ProjectInfo;
import cn.iocoder.yudao.module.xkfz.domain.excel.entity.Standard;
import cn.iocoder.yudao.module.xkfz.domain.excel.po.ProjectInfoPo;
import cn.iocoder.yudao.module.xkfz.domain.excel.po.StandardPo;
import cn.iocoder.yudao.module.xkfz.service.excel.ProjectInfoService;
import cn.iocoder.yudao.module.xkfz.service.excel.StandardService;
import cn.iocoder.yudao.module.xkfz.util.ExcelHeaderExtractor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * @Description 课题信息表
 * @Author ZWC
 * @Date 2024/5/13 13:38
 */
@RestController
@RequestMapping("projectInfo")
public class ProjectInfoController {

    @Autowired
    private ProjectInfoService projectInfoService;

    @PostMapping("importStandard")
    public CommonResult<Boolean> importStandard(@RequestParam("file") MultipartFile file,@RequestParam("year")  String year
            ,@RequestParam("indexId")  String indexId) throws IOException {
        List<ProjectInfo> list = ExcelUtils.read(file, ProjectInfo.class);
        return success(projectInfoService.importProjectInfo(list, year, indexId));
    }

    @GetMapping("selectPage")
    public CommonExcelResult<PageResult<ProjectInfo>>  selectPage (ProjectInfoPo reqVO){
        List<HashMap<String, String>> headerList = ExcelHeaderExtractor.getHeaderList(ProjectInfo.class);
        return CommonExcelResult.success(projectInfoService.selectPage(reqVO), headerList);
    }
    @PostMapping("insert")
    public CommonResult<Boolean> insert(ProjectInfo projectInfo){
        return success(projectInfoService.insert(projectInfo));
    }
    @PostMapping("update")
    public CommonResult<Boolean> update(ProjectInfo projectInfo){
        return success(projectInfoService.update(projectInfo));
    }

    @PostMapping("delete")
    public CommonResult<Boolean> delete(String id){
        return success(projectInfoService.delete(id));
    }
}
